package com.shuoyue.ycgk.ui.mine.learnprogress;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.BaseMvpFragment;
import com.shuoyue.ycgk.entity.LessonProcess;
import com.shuoyue.ycgk.entity.Type;
import com.shuoyue.ycgk.ui.mine.collection.CollectionListActivity;
import com.shuoyue.ycgk.ui.mine.learnprogress.contract.FragmentLearnProcessContract;
import com.shuoyue.ycgk.ui.mine.mynote.NotePagerActivity;
import com.shuoyue.ycgk.ui.mine.mypaperset.MyPaperGroupActivity;
import com.shuoyue.ycgk.ui.mine.wrong.WrongListActivity;
import com.shuoyue.ycgk.views.SportProgressView;

import butterknife.BindView;
import butterknife.OnClick;

public class FragmentLearnProgress extends BaseMvpFragment<FragmentLearnProcessContract.Presenter>
        implements FragmentLearnProcessContract.View {
    Type topType;
    String title;
    @BindView(R.id.progress)
    SportProgressView progress;
    @BindView(R.id.q_done)
    TextView qDone;
    @BindView(R.id.q_total)
    TextView qTotal;
    @BindView(R.id.right_rate)
    TextView rightRate;
    @BindView(R.id.wrong_num)
    TextView wrongNum;
    @BindView(R.id.note_num)
    TextView noteNum;
    @BindView(R.id.collection_num)
    TextView collectionNum;
    @BindView(R.id.questionset_num)
    TextView questionsetNum;
    @BindView(R.id.progressText)
    TextView progressText;


    public static FragmentLearnProgress getInstance(Type type) {
        FragmentLearnProgress fragment = new FragmentLearnProgress();
        fragment.title = type.getName();
        Bundle bundle = new Bundle();
        bundle.putSerializable("type", type);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void initParams(Bundle bundle) {
        topType = (Type) bundle.getSerializable("type");
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_learn_progress;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        mPresenter = new FragmentLearnProcessContract.Presenter();
        mPresenter.attachView(this);
        mPresenter.getProgressInfo(topType.getId());
    }

    @Override
    public String getTitle() {
        return title;
    }

    @Override
    public void setLessonProcess(LessonProcess lessonProcess) {
        progress.setProgress(lessonProcess.getTotalPercent());
        progressText.setText(String.valueOf(lessonProcess.getTotalPercent() == 0 ? "0"
                : lessonProcess.getTotalPercent()));
        qDone.setText(String.valueOf(lessonProcess.getQuestionNum()));
        qTotal.setText(String.valueOf(lessonProcess.getSetQuestionNum()));
        rightRate.setText(String.valueOf(lessonProcess.getAccuracy()));//正确率 accuracy
        wrongNum.setText(String.valueOf(lessonProcess.getWrongNum()));
        noteNum.setText(String.valueOf(lessonProcess.getNoteNum()));
        collectionNum.setText(String.valueOf(lessonProcess.getCollectQuestionNum()));
        questionsetNum.setText(String.valueOf(lessonProcess.getCollectSubjectNum()));

    }

    @OnClick({R.id.lay_wrong_num, R.id.lay_note_num, R.id.lay_collection_num, R.id.lay_questionset_num})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.lay_wrong_num:
                WrongListActivity.start(mActivity, topType.getId());
                break;
            case R.id.lay_note_num:
                NotePagerActivity.start(mActivity, topType.getId());
                break;
            case R.id.lay_collection_num:
                CollectionListActivity.start(mActivity, topType.getId());
                break;
            case R.id.lay_questionset_num:
                MyPaperGroupActivity.start(mContext, topType.getId());
                break;
        }
    }
}
